﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="grdGuests.ascx.cs" Inherits="GUESTSMANAGEMENT.View.Guets.grdGuests" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<%@ Register Src="~/View/Guets/frmGuets.ascx" TagName="Guests" TagPrefix="GMGuests" %>

<ext:ScriptManagerProxy ID="ScriptManagerProxy" runat="server">
</ext:ScriptManagerProxy>

<script type="text/javascript">
    function alertMessage() {
        guestsGridPanel = eval('<%=guestsGridPanel.ClientID%>');
        if (guestsGridPanel.hasSelection())
            return "Confirma Exclusão? <br> <b>" + guestsGridPanel.getSelectionModel().getSelected().data.NMGUESTS + "</b>";

    }

    var getGuestsId = function(grid, rowIndex, columnIndex, e) {
        var t = e.getTarget();
        var record = grid.getStore().getAt(rowIndex);
        var columnId = grid.getColumnModel().getColumnId(columnIndex);
        var columnValue = grid.getColumnModel().getDataIndex(3);
        var id = record.get(columnValue);
        document.getElementById("GMGuests_txt_idGuests").value = id;
    }
</script>

<ext:DesktopWindow ID="winGrdGuests" runat="server" Collapsible="true" Icon="Group" Title="Convidados" Width="588" Height="400">
    <Body>
        <ext:Hidden ID="txt_idGuests" runat="server"></ext:Hidden>
        <ext:Store ID="guestsStore" runat="server" OnRefreshData="Refresh" RefreshAfterSaving="Auto">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="CDGUESTS" />
                        <ext:RecordField Name="NMGUESTS" />
                        <ext:RecordField Name="NMMAIL" />
                        <ext:RecordField Name="NMPHONE" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store> 
        <ext:FitLayout ID="FitLayout1" runat="server">
            <ext:GridPanel ID="guestsGridPanel" 
                runat="server"
                StoreID="guestsStore"
                StripeRows="true"
                Width="450" 
                Height="290"
                AutoExpandColumn="guestsName">
                <TopBar>
                    <ext:Toolbar ID="ToolBar1" runat="server">
                        <Items>
                            <ext:ToolbarButton ID="btnNewGuests" runat="server" Icon="GroupAdd">
                                <Listeners>
                                    <Click Handler="newGuests();" />
                                </Listeners>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipNewGuests" runat="server" Html="Novo Convidado"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnEditGuests" runat="server" Icon="GroupEdit" Enabled="false">
                                <AjaxEvents>
                                    <Click OnEvent="EditGuests" >
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{guestsGridPanel}.getSelectionModel().getSelected().data.CDGUESTS" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipEditGuests" runat="server" Html="Editar Convidado"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnExcluir" runat="server" Icon="GroupDelete" Enabled="false">                     
                                <AjaxEvents>
                                    <Click OnEvent="ConfirmDeleteGuests">                                        
                                        <Confirmation ConfirmRequest="true" 
                                                      Title="Alerta"                                                                                                  
                                                      BeforeConfirm="config.confirmation.message = alertMessage()"                                                       
                                        />
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{guestsGridPanel}.getSelectionModel().hasSelection() ? #{guestsGridPanel}.getSelectionModel().getSelected().data.CDGUESTS : -1" Mode="Raw" />
                                        </ExtraParams>                                        
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipDeleteGuests" runat="server" Html="Excluir Convidado"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="guestsName" Header="Nome" Width="200" DataIndex="NMGUESTS" Sortable="true" />
                        <ext:Column ColumnID="guestsEmail" Header="E-mail" Width="150" DataIndex="NMMAIL" Sortable="true" />
                        <ext:Column ColumnID="guestsPhone" Header="Telefone" Width="100" DataIndex="NMPHONE" Sortable="true" />
                        <ext:Column ColumnID="guestsCDGUESTS" Hidden="true" Header="Editar" Width="100" Sortable="true" DataIndex="CDGUESTS" Fixed="true" MenuDisabled="true" Align="Center" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionMode" runat="server">
                        <Listeners>
                            <RowSelect Handler="#{btnExcluir}.enable(); #{btnEditGuests}.enable();" />                             
                            <RowDeselect Handler="if (!#{guestsGridPanel}.hasSelection()) {#{btnExcluir}.disable(); #{btnEditGuests}.disable();}" />                
                        </Listeners>                       
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <CellDblClick />
                    <CellClick Fn="getGuestsId" />
                </Listeners>
                <AjaxEvents>
                    <CellDblClick OnEvent="EditGuests" Failure="Ext.MessageBox.alert('Erro Leitura Banco de Dados', 'Error ocorreu no Ajax Event!');">
                        <EventMask ShowMask="true" Msg="Carregando..." Target="CustomTarget" CustomTarget="={#{guestsGridPanel}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="#{guestsGridPanel}.getSelectionModel().getSelected().data.CDGUESTS" Mode="Raw" />
                        </ExtraParams>
                    </CellDblClick>
                </AjaxEvents>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolBar ID="PagingToolBar" runat="server" PageSize="10" StoreID="guestsStore" />
                </BottomBar>
            </ext:GridPanel>
        </ext:FitLayout>
        <GMGuests:Guests ID="GMGuests" runat="server" />
    </Body>
</ext:DesktopWindow>
